package com.fowo.api.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fowo.api.entity.StockInProduct;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.plugin.Intercepts;

import java.util.List;

@Mapper
public interface StockInProductExpandMapper extends BaseMapper<StockInProduct> {

    @Select("SELECT unit_price,\n" +
            "\tcost_price,\n" +
            "\tgram_weight,\n" +
            "\tmain_unit_price\n" +
            "\t,labor_costs\n" +
            "\t,accessories_price,\n" +
            "\ts1.supplier,\n" +
            "\ts.product_id\n" +
            "from  stock_in_product s\n" +
            "LEFT JOIN stock_in s1 on s1.id=s.parent_stock_in_id\n" +
            "where s.del_flag=0 and s1.del_flag=0 and s1.`status`=1 and s1.supplier=#{supplierId, jdbcType=BIGINT} and  s.product_id=#{productId, jdbcType=BIGINT}   ORDER BY s1.warehousing_date DESC  LIMIT 1")
//    @Select("select * from stock_in_product where id = #{supplierId, jdbcType=BIGINT}")
    StockInProduct  selectStockInProduct(Long supplierId,Long productId);

    @Select("SELECT unit_price,\n" +
            "\tcost_price,\n" +
            "\tgram_weight,\n" +
            "\tmain_unit_price\n" +
            "\t,labor_costs\n" +
            "\t,accessories_price,\n" +
            "\ts1.warehousing_date create_time,\n" +
            "\ts1.supplier,\n" +
            "\ts.product_id\n" +
            "from  stock_in_product s\n" +
            "LEFT JOIN stock_in s1 on s1.id=s.parent_stock_in_id\n" +
            "where s.del_flag=0 and s1.del_flag=0 and s1.`status`=1 and s1.supplier=#{supplierId, jdbcType=BIGINT} and  s.product_id=#{productId, jdbcType=BIGINT}  " +
            " ORDER BY s1.warehousing_date DESC ")
//    @Select("select * from stock_in_product where id = #{supplierId, jdbcType=BIGINT}")
    Page<StockInProduct> selectStockInProductList(Page page, Long supplierId, Long productId);
}
